package com.ccb.jyzx.expand.tiantouonline.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * 日期工具类
 * @projectName: extend
 * @author: jianghaolin
 * @date: 2019/11/22
 * @version: 1.0
 */
public class DateUtils {

    static Logger logger= LoggerFactory.getLogger(DateUtils.class);

    /**
     * 获取当前年
     * @return
     */
    public static String nowYear(){
        SimpleDateFormat df = new SimpleDateFormat("yyyy");
        Date now = new Date(System.currentTimeMillis());
        String nowDay = df.format(now);
        return nowDay;
    }

    /**
     * 获取当前日
     * @return
     */
    public static String nowDay(){
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        Date now = new Date(System.currentTimeMillis());
        String nowDay = df.format(now);
        return nowDay;
    }

    /**
     * 获取系统昨天日
     * @return
     */
    public static String getYestoday(){
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1);
        Date date = calendar.getTime();
        DateFormat df = new SimpleDateFormat("yyyyMMdd");
        return df.format(date);
    }

    /**
     * 获取上午（01） 下午（02）
     * @return
     */
    public static String getMorningOrAfternoone(){
        String batch = "";
        GregorianCalendar ca = new GregorianCalendar();
        if (ca.get(GregorianCalendar.AM_PM) == 0) {
            //上午
            batch = ConstantUtil.BATCH_AM;
        }else{
            //下午
            batch = ConstantUtil.BATCH_PM;
        }
        return batch;
    }

}
